package com.ww.java7.fileattr;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.*;

public class FileAttrDemo {

    public static void main(String[] args) throws IOException {
        Path path = Paths.get("D:/test/test.txt");
        BasicFileAttributeView fileAttributeView = Files.getFileAttributeView(path, BasicFileAttributeView.class);
        BasicFileAttributes basicFileAttributes = fileAttributeView.readAttributes();
        FileTime creationTime = basicFileAttributes.creationTime();
        FileTime lastModifiedTime = basicFileAttributes.lastModifiedTime();
        FileTime lastAccessTime = basicFileAttributes.lastAccessTime();
        System.out.println("创建时间：" + creationTime);
        System.out.println("上次修改时间：" + lastModifiedTime);
        System.out.println("上次访问时间：" + lastAccessTime);

        boolean directory = basicFileAttributes.isDirectory();
        boolean regularFile = basicFileAttributes.isRegularFile();
        boolean symbolicLink = basicFileAttributes.isSymbolicLink();
        System.out.println("是否目录：" + directory);
        System.out.println("是否普通文件：" + regularFile);
        System.out.println("是否符号连接：" + symbolicLink);

        long size = basicFileAttributes.size();
        System.out.println("文件大小：" + size);

        DosFileAttributeView dosFileAttrView = Files.getFileAttributeView(path, DosFileAttributeView.class);
        boolean system = dosFileAttrView.readAttributes().isSystem();
        System.out.println("文件是否相同文件：" + system);
    }
}
